<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="组织ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="organizationId">
              <a-input v-model="model.organizationId" placeholder="请输入组织ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="部门ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deptId">
              <a-input v-model="model.deptId" placeholder="请输入部门ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processId">
              <a-input v-model="model.processId" placeholder="请输入工序ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工序名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processName">
              <a-input v-model="model.processName" placeholder="请输入工序名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="类型(in:输入 out:输出)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processType">
              <a-input v-model="model.processType" placeholder="请输入类型(in:输入 out:输出)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowName">
              <a-input v-model="model.flowName" placeholder="请输入流程名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowType">
              <a-input v-model="model.flowType" placeholder="请输入流程类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程类型名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowTypeName">
              <a-input v-model="model.flowTypeName" placeholder="请输入流程类型名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowNumber">
              <a-input-number v-model="model.flowNumber" placeholder="请输入流程数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowUnit">
              <a-input v-model="model.flowUnit" placeholder="请输入流程单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="流程单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowUnitName">
              <a-input v-model="model.flowUnitName" placeholder="请输入流程单位名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowDataSources">
              <a-input-number v-model="model.flowDataSources" placeholder="请输入数据来源" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数据说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="flowDataDescription">
              <a-input v-model="model.flowDataDescription" placeholder="请输入数据说明"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="碳排因子ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="emissionFactorId">
              <a-input v-model="model.emissionFactorId" placeholder="请输入碳排因子ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运输重量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weight">
              <a-input-number v-model="model.weight" placeholder="请输入运输重量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运输重量单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weightUnit">
              <a-input v-model="model.weightUnit" placeholder="请输入运输重量单位"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运输重量单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weightUnitName">
              <a-input v-model="model.weightUnitName" placeholder="请输入运输重量单位名称"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CyFootprintProcessFlowForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/.cyFootprintProcessFlow/cyFootprintProcessFlow/add",
          edit: "/.cyFootprintProcessFlow/cyFootprintProcessFlow/edit",
          queryById: "/.cyFootprintProcessFlow/cyFootprintProcessFlow/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>